{{define "title"}}{{.topic.title}} {{end}}
{{define "seo"}}<meta name="keywords" content="{{.setting.SeoKeywords}}">
<meta name="description" content="{{substring .topic.content 200 ""}}">{{end}}
{{define "content"}}
<div class="row">
    <div class="col-md-9 col-sm-6">
        <div class="sep20"></div>

        <ol class="breadcrumb">
            <li><a href="/">首页</a></li>
            <li><a href="/topics">主题</a></li>
            <li><a href="{{if .topic.node.ename}}/go/{{.topic.node.ename}}{{else}}/topics/node/{{.topic.node.nid}}{{end}}">{{.topic.node.name}}</a></li>
        </ol>
        <div class="page">
            <div class="box_white">
                <div class="title">
                    <div class="pull-right">
                        <a href="/user/{{.topic.user.Username}}" title="{{.topic.user.Username}}">
                            <img src="{{gravatar .topic.user.Avatar .topic.user.Email 62 .is_https}}" alt="{{if .topic.user.Name}}{{.topic.user.Name}}{{else}}{{.topic.user.Username}}{{end}}" width="62px" height="62px">
                            {{if .topic.user.IsVip}}
                                <span class="article-prosign"> &#9733 VIP</span>
                            {{end}}
                        </a>
                    </div>
                    <h1>
                        {{.topic.title}}
                    </h1>
                    <small class="c9">
                        <a href="/user/{{.topic.user.Username}}">{{.topic.user.Username}}</a> · <span title="{{.topic.ctime}}" class="timeago"></span> · {{add .topic.view 1}} 次点击 ·
                        <span class="timeago" title="{{.cur_time}}"></span> 开始浏览&nbsp; &nbsp;
                        {{if canEdit .me .topic}}
                        <a class="op" href="/topics/modify?tid={{.topic.tid}}" title="编辑">编辑</a>
                        {{else if and (eq .me.Uid .topic.user.Uid) (lt (len .appends) 3) }}
                        <a class="op" href="/append/topic/{{.topic.tid}}" title="附言">附言</a>
                        {{end}}
                        {{if and (canPublish .me.DauAuth 101) (not .topic.top)}}
                        <a id="set-top" class="op" href="/topics/set_top?tid={{.topic.tid}}" title="置顶">置顶</a>
                        {{end}}
                    </small>
                </div>
                {{if gt (distanceDay .topic.ctime) 100 }}
                <div class="outdated">这是一个创建于 <span title="{{.topic.ctime}}" class="timeago"></span> 的主题，其中的信息可能已经有所发展或是发生改变。</div>
                {{end}}
                <div class="cell">
                    {{if eq .topic.permission 1}}
                        {{if .me.Status}}
                            <div class="content">{{.topic.content}}</div>
                        {{else}}
                            <div style="font-size: 1.2em;">作者设置必须登录才能查看，<a href="/account/login?redirect_uri=/topics/{{.topic.tid}}">请登录</a>；如没有账号，<a href="/account/register">请注册</a></div>
                        {{end}}
                    {{else if eq .topic.permission 3}}
                        {{if or .me.IsVip .me.IsRoot (eq .topic.uid .me.Uid)}}
                            <div class="content">{{.topic.content}}</div>
                        {{else}}
                            <div style="font-size: 1.2em;">
                                <p>作者设置付费用户才能查看，加入Go中文网创建的<a href="https://t.zsxq.com/BM72RZR" title="知识星球" target="_blank">知识星球</a>自动成为付费用户（加入后星球私信告知网站用户名）。</p>
                                <img src="{{.static_domain}}/static/img/zsxq.jpg" alt="知识星球" class="img-responsive">
                                <p>或者给我们转账成为付费用户，有效期一年，限时优惠：68元/年</p>
                                <img src="{{.static_domain}}/static/img/wxpay68.jpg" alt="转账付费" class="img-responsive">
                            </div>
                        {{end}}
                    {{else}}
                        <div class="content">{{.topic.content}}</div>
                    {{end}}
                </div>
                {{range $i, $append := .appends}}
                <div class="subtle">
                    <span class="cc">第 {{add $i 1}} 条附言 &nbsp;·&nbsp; <span class="timeago" title="{{$append.CreatedAt}}"></span></span>
                    <div class="sep5"></div>

                    <div class="append_content">
                        <div class="content markdown-body">{{$append.Content}}</div>
                    </div>

                </div>
                {{end}}

                <div class="content-buttons">
                    <div class="pull-right c9 f11" style="line-height: 12px; padding-top: 3px; text-shadow: 0px 1px 0px #fff;">{{add .topic.view 1}} 次点击 &nbsp;{{if .topic.like}}∙&nbsp; {{.topic.like}} 赞 &nbsp; {{end}}</div>
                    <a class="tb collect" href="javascript:;" title="{{if .hadcollect}}取消收藏{{else}}加入收藏{{end}}" data-objid="{{.topic.tid}}" data-objtype="0" data-collect="{{.hadcollect}}">{{if .hadcollect}}取消收藏{{else}}加入收藏{{end}}</a>
                    <a href="javascript:" onclick="window.open('http://service.weibo.com/share/share.php?url=http{{if .is_https}}s{{end}}://{{.setting.Domain}}/topics/{{.topic.tid}}&title='+encodeURIComponent('{{.setting.Name}} - {{.topic.title}} by {{.topic.user.Username}} #golang#'), '_blank', 'width=550,height=370');" class="tb">微博</a>
                    <div id="content-thank">
                        <a class="tb" href="javascript:;" title="{{if .likeflag}}取消赞{{else}}赞{{end}}" data-objid="{{.topic.tid}}" data-objtype="0" data-flag="{{.likeflag}}">{{if .likeflag}}取消赞{{else}}赞{{end}}</a>
                    </div>
                </div>
            </div>
            <!-- content END -->
            <div class="sep20"></div>

            <!-- 评论列表 -->
            <div id="replies" class="box_white">
                <div class="cell">
                    <div class="pull-right" style="margin: -3px -5px 0px 0px;">
                    {{if .topic.tags}}
                        {{$tags := explode .topic.tags ","}}
                        {{range $tags}}
                        <a href="/tag/{{.}}" class="tag"><li class="fa fa-tag"></li> {{.}}</a>
                        {{end}}
                    {{end}}
                    </div>
                    <span class="c9"><span class="cmtnum">{{.topic.reply}}</span> 回复 {{if .topic.reply}}&nbsp;<strong class="snow">|</strong> &nbsp;直到 {{.topic.lastreplytime}}{{end}}</span>
                </div>
                {{include "common/comment-page.html" .}}
                <div class="comment-list cell" data-objid="{{.topic.tid}}" data-objtype="0" {{if .me.Uid}}data-username="{{.me.Username}}" data-uid="{{.me.Uid}}" data-avatar="{{gravatar .me.Avatar .me.Email 48 .is_https}}"{{end}}>
                    <div class="words hide"><div class="text-center">暂无回复</div></div>
                </div>
                {{include "common/comment-page.html" .}}
            </div>

            {{if .can_view}}
                <!-- 评论框 -->
                {{template "comment" .}}
            {{end}}

            {{include "common/view_stat.html" .}}

        </div>
    </div>
    <div class="col-md-3 col-sm-6">
        <div class="sep20"></div>

        {{include "common/my_info.html" .}}

        {{if .pos_ad.right1}}
        <div class="box_white sidebar" id="ad-right1">
            {{if eq .pos_ad.right1.AdType 0}}
                {{noescape .pos_ad.right1.Code}}
            {{end}}
        </div>
        {{end}}

        {{include "sidebar/view_rank.html" (parseJSON `{"rank_title":"今日阅读排行","objtype":0,"limit":10,"rank_type":"today"}`)}}

        {{if .pos_ad.right2}}
        <div class="box_white sidebar" id="ad-right2">
            {{if eq .pos_ad.right2.AdType 0}}
                {{noescape .pos_ad.right2.Code}}
            {{end}}
        </div>
        {{end}}

        {{include "sidebar/view_rank.html" (parseJSON `{"rank_title":"一周阅读排行","objtype":0,"limit":10,"rank_type":"week"}`)}}

    </div>
</div>
{{end}}
{{define "css"}}
<link href="{{.static_domain}}/static/dist/css/table.min.css" media="screen" rel="stylesheet" type="text/css">
{{include "cssjs/prism.css.html" .}}

{{end}}

{{define "js"}}
<script type="text/javascript" src="{{.static_domain}}/static/dist/js/topics.min.js"></script>
<script type="text/javascript">
// 需要加载的侧边栏
SG.SIDE_BARS = [
    "/topics/recent",
    "/articles/recent",
    "/resources/recent",
    "/rank/view"
];

var keyprefix = 'topic';
var objid = {{.topic.tid}};

$(function(){
    new SG.Topics().parseContent($('.page .content'));

    $('code[class*="language-"]').parent('pre').addClass('line-numbers');

    // 文本框自动伸缩
    $('.need-autogrow').autoGrow();

    // 有权限查看才加载评论
    {{if .can_view}}
        loadComments();
    {{end}}

    // 链接，add target=_blank
    $('#wrapper .content').on('mousedown', 'a', function(evt){
        var url = $(this).attr('href');
        $(this).attr('target', '_blank');
    });

    $('#set-top').on('click', function(evt) {
        evt.preventDefault();

        var url = $(this).attr('href');
        $.post(url, {}, function(result) {
            if (result.ok) {
                comTip("置顶成功！");
            } else {
                comTip(result.msg);
            }
        });

        return false;
    });
});
</script>

{{include "cssjs/prism.js.html" .}}

{{if .pos_ad.right1}}
    {{if eq .pos_ad.right1.AdType 1}}
        {{noescape .pos_ad.right1.Code}}
    {{end}}
{{end}}

{{if .pos_ad.right2}}
    {{if eq .pos_ad.right2.AdType 1}}
        {{noescape .pos_ad.right2.Code}}
    {{end}}
{{end}}

{{end}}
